<template>
  <a-card title="我的信息">
    <a-descriptions :column="2">
      <a-descriptions-item label="用户名">{{
        userInfo.userName
      }}</a-descriptions-item>
      <a-descriptions-item label="积分">{{
        userInfo.score
      }}</a-descriptions-item>
      <a-descriptions-item label="AC数">{{
        userInfo.acCount
      }}</a-descriptions-item>
      <a-descriptions-item label="提交数">{{
        userInfo.submitCount
      }}</a-descriptions-item>
      <a-descriptions-item label="AC率">{{ acRate }}%</a-descriptions-item>
    </a-descriptions>
  </a-card>
</template>

<script setup>
import { ref, computed, onMounted } from "vue";
import { UserControllerService } from "../../../generated";

const userInfo = ref({});
const acRate = computed(() =>
  userInfo.value.submitCount
    ? ((userInfo.value.acCount / userInfo.value.submitCount) * 100).toFixed(2)
    : "0.00"
);

onMounted(async () => {
  const res = await UserControllerService.getUserRankInfo();
  if (res.code === 0) userInfo.value = res.data;
});
</script>
